// in运算符 确定对象是否具有带名称的属性: in运算符
// 如果指定的属性在指定对象或原型链中,则in返回true

type Fish = { name: string, swim: () => void }
type Dog = { name: string, run: () => void }

function move(animal: Fish | Dog) {
    if ('swim' in animal) {
        animal.swim()
    } else {
        animal.run()
    }
}

const dog: Dog = {
    name: 'a',
    run(){
        console.log(this.name+" is run");
    }
}
move(dog);  //传入函数一个对象和ajax形式类似
export {}